use rand::distributions::Distribution;
use rand::distributions::Uniform;
use rand::Rng;

fn main() {
    let mut rng = rand::thread_rng();
    println!("Integer: {}", rng.gen_range(0..10));
    println!("Float: {}", rng.gen_range(0.0..10.0));

    // Uniform 模块可得到均匀分布的值, 相同范围内重复生成数字性能更好
    let mut rng = rand::thread_rng();
    let mut die = Uniform::try_from(1..7).unwrap();

    loop {
        let throw = die.sample(&mut rng);
        println!("Roll the die: {}", throw);
        if throw == 6 {
            break;
        }
    }
}
